﻿var corpGuid;
var areaCode;
var empGuid;
var status;
var selAll;
var DropQual;
var DropSubQual;
var DropCardType;
var ok = 0;
var typeFlag;
var tFlag;
var model;
var editStatus;
var backUrl;
var userRole;
var roleId;
var manual;
var sysCode;
// var funcCode='';
var empUpImgExt; //安全考核证图片
var empExt; //安全考核证
var CertCodeExt; //安全考核证编号
var eduGuid; //安全考核证guid
var CloseBtn = "0"; //是否显示关闭按钮
var msg; //窗口提示

/*绑定按钮事件*/
function BindBtnClick() {
    //人员资格
    $("#QualAdd").click(function () {
        ShowAddForm("../Person/PersonEmpCertInfo.aspx?empGuid=" + empGuid, 810,650);
    });
    $("#QualEdit").click(function () {
        ShowEditForm("../Person/PersonEmpCertInfo.aspx?empGuid=" + empGuid + "&certGuid=", "EmpQualities", 810, 650);
    });
    $("#QualDel").click(function () {
        EmpDel("QualitieDel", "EmpQualities");
    });
    //身份证
    $("#txtCard").blur(function () {
        IDCardCheck();
    });

    //工作经历
    $("#WorkAdd").click(function () {
        ShowAddForm("../Person/PersonEmpWorkInfo.aspx?empGuid=" + empGuid, 800,400);
    });
    $("#WorkEdit").click(function () {
        ShowEditForm("../Person/PersonEmpWorkInfo.aspx?empGuid=" + empGuid + "&workId=", "EmpWork", 800,400);
    });
    $("#WorkDel").click(function () {
        EmpWorkDel("ExperienceDel", "EmpWork");
    });
   
    //保存基本信息
    $("#SaveEmpInfo").click(function () {
        EmpInfoSave("SaveEmpInfo");
    });
    //上传照片
    $("#imgUpload").click(function () {
        ShowUpForm("../Person/PersonUploadFile.aspx?filename=" + empGuid, 550, 520);
        return false;
    });
    //职称下拉列表
    selPostAll();
    $("#" + DropQual).change(function () {
        SelChange();
    });
    //返回列表
    if (model == "0") {
        $("#btnRet").show();
        $("#btnRet").click(function () {
            window.location = "../Person/PersonEmpList.aspx?typeFlag=" + typeFlag;
        });
    } else {
        $("#btnRet").hide();
    }
    //上报
    $("#SubmitEmp").click(function () {
        EmpSubmit();
    });
    //设置管理人员
//        $("#SubmitFlag").click(function () {
//            EmpToManager();
//        });
    //审核
    $("#EmpAudit").click(function () {
        ShowUpForm("../Person/PersonEmpAudit.aspx?empGuid=" + empGuid + "&corpGuid=" + corpGuid + "&areaCode=" + areaCode, 820, 420);
        return false;
    });
    //显示图片预览和上传按钮
    EmpImgBtnClick();
    ToImgZoom();
       
//        if (model == 0) {
//            $("#closeDiv").hide();
//        } else {
//            $("#btnClose").click(function () {
//                returnToParent();
//        });
    //        }
    //人员手册
    $("#QualscAdd").click(function () {
        ShowAddForm("../Person/PersonEmpCertInfo.aspx?empGuid=" + empGuid + "&manual=" + manual, 810, 650);
    });
    $("#QualscEdit").click(function () {
        ShowEditForm("../Person/PersonEmpCertInfo.aspx?empGuid=" + empGuid + "&manual=" + manual + "&certGuid=", "EmpQualitiesSC", 810, 650);
    });
    $("#QualscDel").click(function () {
        EmpQualscDel("QualitieDel", "EmpQualitiesSC");
    });
    $("#Printbtn").click(function () {
        EmpQualscPrint("EmpQualitiesSC");
    });
    //关闭窗口按钮事件
    OnCloseChangeEmp();
}
/*安全生产许可证及相关项显示*/
function EmpExtShowStatus() {
    $("#"+empUpImgExt).show();
    $("#"+empExt).show();
}
/*安全生产许可证及相关项显示*/
function EmpExtHideStatus() {
    $("#"+empUpImgExt).hide();
    $("#"+empExt).hide();
} 
 
/*打开添加窗口*/
function ShowUpForm(u,w,h,win) {
    win = win || this;
    $.ligerDialog.open({ url: u, width: w, height: h, title: '', buttons: [{ text: '关闭', onclick: function (item, dialog) { dialog.close(); } }] });
    win.ChildDialogWin = this;
    return false;
}
function ShowAddForm(u, w,h,win) {
    if (ok == 0) {
        // alert("请先添加人员基本信息！");
        OpenAlert("请先填写人员基本信息，点击【保存】按钮之后，再录入其它信息！");
        return false;
    }
    win = win || this;
    $.ligerDialog.open({ url: u, width: w, height: h, title: '', isResize: true });
    win.ChildDialogWin = this;
    return false;
}
/*打开编辑窗口*/
function ShowEditForm(u, tbodyname,w,h) {
    if (ok ==0) {
        OpenAlert("请先填写人员基本信息，点击【保存】按钮之后，再录入其它信息！");
        return false;
    }
    var keyId = GetKeyID(tbodyname);
    if (keyId == "") {
        OpenAlert("请选择操作项！");
        return false;
    }
    if (keyId.indexOf(",") > 0) {
        OpenAlert("只能选择一个操作项！");
        return false;
    }
    win = top || this;
    $.ligerDialog.open({ url: u + keyId, width: w, height: h, title: '', isResize: true });
    win.ChildDialogWin = this;
    return false;
}
///取得评审资格小项
function selPostAll() {
    $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", { "action": "PostPszg", "rand": Math.random() }, function (data) {
        selAll = data;
    });
}
///评审资格选择
function SelChange() {
    var post1 = $("#" + DropQual).val();
    $("#" + DropSubQual).empty();
    $("#" + DropSubQual).append("<option value='-1'>请选择</option>");
    if (post1 == "-1") {
        return;
    }
    if (selAll == null || selAll == "undefined") {
        return;
    }
    for (var x in selAll) {
        if (x.length <= 2) {
            continue;
        }
        if (x.substring(0, 2) == post1) {
            $("#" + DropSubQual).append("<option value='" + x + "'>" + selAll[x] + "</option>");
        }
    }
}
///验证身份证号
function IDCardCheck() {
    var IDCard = $("#txtCard").val() || "";

    if (IDCard == "") {
        return false;
    }
    //验证格式
    if ($("#" + DropCardType).val() == "1") {
        if (!isIdCardNo("#txtCard")) {
            return false;
        }
    }
    $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", { "action": "CardCheck", "IDCard": IDCard, "empGuid": empGuid, "areaCode": areaCode, "corpGuid": corpGuid, "rand": Math.random() }, function (data) {
        var result = data.Result;
        //正常
        if (result) {
            $("#txtBirthday").val(GetBirthday($("#txtCard").val()));
            return false;
        } //导入人员提示
        var rvalue = data.ReturnValue;
        if (rvalue != null && rvalue.length > 0) {
            if (editStatus != "0")
            { return false; }
            var emp = rvalue.split(",");
            $("#hdTmpGuid").val($.trim(emp[0]));
            OpenConfirm(data.Message + "导入人员[" + emp[1] + "]的信息，可以快速完成信息添加，是否导入？");
        } else {
            OpenAlert(data.Message); //异常
        }
        // $("#SaveEmpInfo").attr("disabled", "disabled");
    });
}

///身份证重复提示
function OpenConfirm(arg) {
    radconfirm(arg, confirmCallBackFn, 430, 200, null, '提示');
    return false;
}
  
///身份证导入人员信息
function confirmCallBackFn(arg) {
    if (arg) {
        empGuid = $("#hdTmpGuid").val();
        status = "1";
        $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", { "action": "AddTypeFlag", "empGuid": empGuid, "typeFlag": typeFlag, "areaCode": areaCode, "rand": Math.random() }, function (data) {
            if (data.Result) {
                EmpOpenAlertFn(data.Message, EmpCertalertCallBackFn);
                return false;
            } else {
                OpenAlert(data.Message);
                GetEmpUserLog(1, 10);
            }
        });
    }
    return false;
}
//显示导入信息
function EmpOpenAlertFn(text, alertCallBackFn1) {
    radalert(text, 330, 150, '提示', alertCallBackFn1, null);
    return false;
}
//显示导入人员信息
function EmpCertalertCallBackFn() {
    var url = window.location.href; 
    if (url.indexOf("?") > 0) {
        url = url.substring(0, url.indexOf("?") + 1) + "typeFlag=" + typeFlag + "&empGuid=" + empGuid + "&close=" + CloseBtn+"&msg="+msg;
    } else {
        url = url + "?empGuid=" + empGuid;
    }
    window.location = url;
}//end
function EmpDelCheck(tbodyname) {
    if (empGuid == "") {
        OpenAlert("请先添加人员基本信息！");
        return false;
    }
    var keyId = GetKeyID(tbodyname);
    if (keyId == "") {
        OpenAlert("请选择操作项！");
        return false;
    }
    return true;
}
/*删除人员手册*/
function EmpQualscDel(action, tbodyname) {
    if (!EmpDelCheck(tbodyname)) {
        return false;
    }
    var keyId = GetKeyID(tbodyname);//取得选择项
    if (confirm("您确定要删除此信息！")) {
        $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", { "action": action, "empGuid": empGuid, "keyId": keyId, "areaCode": areaCode, "rand": Math.random() }, function (data) {
            OpenAlert(data.Message);
            GetEmpQualitiesSC();
        });
        GetEmpUserLog(1, 10);
    }
    return false;
}

/*删除人员资格*/
function EmpDel(action, tbodyname) {
    if (empGuid == "") {
        OpenAlert("请先添加人员基本信息！");
        return false;
    }
    var keyId = GetKeyID(tbodyname); //取得选择项
    if (keyId == "") {
        OpenAlert("请选择操作项！");
        return false;
    }
    if (confirm("您确定要删除此信息！")) {
        $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", { "action": action, "empGuid": empGuid, "keyId": keyId, "areaCode": areaCode, "rand": Math.random() }, function (data) {
            OpenAlert(data.Message);
            GetEmpQualities();
        });
            GetEmpUserLog(1, 10);
    }
    return false;
}
/*删除工作经历*/
function EmpWorkDel(action, tbodyname) {
    if (empGuid == "") {
        OpenAlert("请先添加人员基本信息！");
        return false;
    }
    var keyId = GetKeyID(tbodyname);
    if (keyId == "") {
        OpenAlert("请选择操作项！");
        return false;
    }
    if (confirm("您确定要删除此信息！")) {
        $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", { "action": action, "empGuid": empGuid, "keyId": keyId, "areaCode": areaCode, "rand": Math.random() }, function (data) {
            OpenAlert(data.Message);
            GetEmpWorkExperience();
            GetEmpUserLog(1, 10);
        });
    }
    return false;
}


/*取得选择的项编号*/
function GetKeyID(tbodyname) {
    var selstr = "";
    $("input[type='checkbox']:checked", $("#" + tbodyname)).each(function () {
        selstr += $(this).attr("id") + ",";
    });
    if (selstr != "") {
        selstr = selstr.substring(0, selstr.length - 1);
    }
    return selstr;
}
//取得上传验证图片列表，固定验证身份证，添加安全考核证编号则验证安全考核证
function GetCheckImg() {
    // sysCode = "";
    var filename = empGuid;
    var funcCode = "PersonID";
    if ($("#" + CertCodeExt).val() != undefined && $("#" + CertCodeExt).val()!="") {
        funcCode += ",PersonKH";
        filename += "," + eduGuid;
    }
    return { "funcCode": funcCode, "filename": filename };

}
///取得未上传图片名
function GetCheckImgTitle(code) {
    var result = "";
    if (code.length > 0) {
        result= $("#empUpImgDiv img[funccode='" + code + "']").eq(0).attr("title");
    }
    return result;
}
/*保存人员基本信息*/
function EmpInfoSave(btnId) {
    //数据验证
    $("#hdempExtId").val(eduGuid);
    var dataValid = CheckControlValid(btnId);
    if (!dataValid) {
        return false;
    }
    //取得验证图片
    var img=GetCheckImg();
    var funcCode = img.funcCode;
    var imgName = img.filename;
    //取得参数
    $("#" + tFlag).val(typeFlag);
    var pageData = {};
    pageData.empGuid = empGuid;
    pageData.areaCode = areaCode;
    pageData.corpGuid = corpGuid;
    var dataStr = GetData(btnId);//取得页面上的所有数据
    pageData.data = dataStr;
    pageData.rand = Math.random();
    if (funcCode.length > 0) {
        pageData.funcCode = funcCode;
        pageData.filename = imgName;
    }
    //提交
    $("#" + btnId).attr("disabled", "disabled");
    if (status == "0") {
        pageData.action = "EmpInfoAdd";
        EmpInfoAdd(pageData, btnId);
    } else {
        pageData.action = "EmpInfoEdit";
        EmpInfoEdit(pageData, btnId);
    }
      
}
/*添加人员基本信息*/
function EmpInfoAdd(pageData, btnId) {
    $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", pageData, function (data) {
        $("#" + btnId).removeAttr("disabled");
        if (data.Result) {
            var rvalue = data.ReturnValue;//操作成功返回用户信息
            empGuid = rvalue.EmpGuid;
            ok = 1;
            status = 1;
              
        } else {
            //未上传的图片提示
            if (data.Message == "img") {
                var text = GetCheckImgTitle(data.ReturnValue);
                OpenAlert("人员相关证件["+text+"]必须上传！");
                return false;
            }
        }
        GetEmpUserLog(1, 10);
        OpenAlert(data.Message);
        //  returnToParent();           
    });
}
  
/*修改人员基本信息*/
function EmpInfoEdit(pageData, btnId) {
    $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", pageData, function (data) {
        $("#" + btnId).removeAttr("disabled");
        //未上传的图片提示
        if (data.Message == "img") {
            var text = GetCheckImgTitle(data.ReturnValue);
            OpenAlert("人员相关证件[" + text + "]必须上传！");
            return false;
        }
        GetEmpUserLog(1, 10);
        OpenAlert(data.Message);        
        // returnToParent();
    });
}
/*取得人员基本信息**/
function GetEmpInfo() {
    $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", { "action": "EmpInfo", "empGuid": empGuid, "areaCode": areaCode, "rand": Math.random() }, function (data) {
        if (data.length == 0 || data == null) {
            OpenAlert("未查询到有效数据！");
            return false;
        }
        if (data.result == 1) {
            OpenAlert(data.message);
            return false;
        }
        var empInfo1 = data.empInfo;//基本信息
        var empPost1 = data.empPost;//职称
        var empExt1 = data.empExt;//安全考核证
        ////人员基本信息
        if (empInfo1 != null && empInfo1.length > 0) {
            for (var i = 0, j = empInfo1.length; i < j; i++) {
                SetControlVal("empInfo", empInfo1[i]);//基本信息页面控件赋值
                if (empInfo1[i].ClassId == "2511" || empInfo1[i].ClassId == "7340") {
                    EmpExtShowStatus();//显示安全考核证
                } else {
                    EmpExtHideStatus();
                }
            }
        }
        ////职称信息
        if (empPost1 != null && empPost1.length > 0) {
            for (var i = 0, j = empPost1.length; i < j; i++) {
                SetControlVal("empPost", empPost1[i]);//职称页面控件赋值
                SelChange();//加载下拉列表
                $("#" + DropSubQual).val(empPost1[i].Post_psZGCode);
            }
        }
        //安全考核证
        if (empExt1 != null && empExt1.length > 0) {
            for (var i = 0, j = empExt1.length; i < j; i++) {
                SetControlVal("empExt", empExt1[i]);//安全考核证页面控件赋值
                //安全考核证guid用于上传图片
                if ($("#hdempExtId").val() != "00000000-0000-0000-0000-000000000000") {
                    eduGuid = $("#hdempExtId").val();//赋值安全考核证guid
                }
            }
        }
        //加载图片事件
        ImgCardShow("");
        PersonKHImgs(eduGuid);//安全考核证图片
    });
    //人员头像
    ImgShow();
}
/*上报人员*/
function EmpSubmit() {
    if (confirm("您确定要上报此人员，上报前请确认信息已保存，上报后信息不可修改！")) {
        var parmer = {};
        parmer.action = "EmpPost";
        parmer.empGuid = empGuid;
        parmer.corpGuid = corpGuid;
        parmer.areaCode = areaCode;
        parmer.message = "人员上报";
        parmer.optType = 4;
        parmer.descr = "";
        parmer.rand = Math.random();
        $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", parmer, function (data) {
               
            if (data.Result) {
                OpenAlertFn(data.Message);
            } else {
                //未上传的图片提示
                if (data.Message == "img") {
                    OpenAlert(data.ReturnValue);
                    return false;
                }
                OpenAlert(data.Message);
            }
        });
    }
}
/*设为管理人员*/
//    function EmpToManager() {
//        $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", { "action": "AddTypeFlag", "empGuid": empGuid, "typeFlag": typeFlag, "areaCode": areaCode, "rand": Math.random() }, function (data) {
//            OpenAlert(data.Message);
//            GetEmpUserLog(1, 10);
//        });
//    }
/*加载日志数据*/
function GetEmpUserLog(pageNo, pageSize) {
    var pageData = {};
    pageData.action = "UserLog";
    pageData.empGuid = empGuid;
    pageData.pageNo = pageNo;
    pageData.pageSize = pageSize;
    pageData.areaCode = areaCode,
    pageData.userRole = userRole;
    pageData.rand = Math.random();
    $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", pageData, function (data) {
        var innerHTML = "";
        $("#EmpLogs").empty();
        $("#list_page").empty();
        var items = data.data;
        allCount = data.pageCount;
        var IsrtDate = "";
        if (items != null && items.length > 0) {
            for (var i = 0, j = items.length; i < j; i++) {
                var item = items[i];
                if (item.IsrtDate != null && item.IsrtDate.length > 10) {
                    IsrtDate = item.IsrtDate.replace("T"," ");
                } else {
                    IsrtDate = item.IsrtDate;
                }
                innerHTML += ' <tr><td>' + item.IsrtUserName + '</td><td>' + item.Content + '</td><td>' + IsrtDate + '</td><tr>';
            }
        }
        $("#EmpLogs").append(innerHTML);
        //分页
        if (allCount > pageSize) {
            var allNo = 0;
            if (allCount > 0 && pageSize > 0) {
                allNo = parseInt(allCount / pageSize);
                if (allCount % pageSize > 0) {
                    allNo++;
                }
            }
            $("#list_page").pager({
                "amount": allCount,
                "allNo": allNo,
                "pageNo": pageNo,
                "pageSize": pageSize,
                "callback": function (n) { GetEmpUserLog(n, pageSize); }
            });
        }

    });
}
/*加载工作经历数据*/
function GetEmpWorkExperience() {
    $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", { "action": "Experience", "empGuid": empGuid, "areaCode": areaCode, "rand": Math.random() }, function (data) {
        var innerHTML = "";
        $("#EmpWork").empty();
        if (data != null && data.length > 0) {
            var BeginDate = "";
            for (var i = 0, j = data.length; i < j; i++) {
                var item = data[i];
                //日期格式化
                if (item.BeginDate != null && item.BeginDate.length > 10) {
                    BeginDate = item.BeginDate.substring(0, 10);
                } else {
                    BeginDate = item.BeginDate;
                }
                innerHTML += ' <tr><td><input  type="checkbox" id="' + item.ID + '"/></td>';
                innerHTML += '<td>' + (i + 1).toString() + '</td><td>' + item.CorpName + '</td><td>' + BeginDate + '</td><td>' + item.EndDate + '</td> <td>' + item.Post + '</td></tr>';
            }
        }
        $("#EmpWork").append(innerHTML);
    });
}

/*加载人员资格证书数据*/
function GetEmpQualities() {
    $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", { "action": "Qualitie", "empGuid": empGuid, "areaCode": areaCode, "rand": Math.random() }, function (data) {
        var innerHTML = "";
        $("#EmpQualities").empty();
        $("#empUpImgDiv .empCertImg").remove();
        if (data != null && data.length > 0) {
            var GetCertificateDate = "";
            var ZsEndDate = "";
            var CLCode = "";
            for (var i = 0, j = data.length; i < j; i++) {
                var item = data[i];
                //日期格式化
                if (item.GetCertificateDate != null && item.GetCertificateDate.length > 10) {
                    GetCertificateDate = item.GetCertificateDate.substring(0, 10);
                } else {
                    GetCertificateDate = item.GetCertificateDate;
                }
                if (item.ZsEndDate != null && item.ZsEndDate.length > 10) {
                    ZsEndDate = item.ZsEndDate.substring(0, 10);
                } else {
                    ZsEndDate = item.ZsEndDate == null ? "" : item.ZsEndDate;
                }
                //编号除null
                CLCode = item.CLCode == null ? "" : item.CLCode;
                innerHTML += ' <tr><td><input  type="checkbox" id="' + item.EducationGUID + '"/></td>';
                innerHTML += '<td>' + item.CertificateName + '</td><td><a onclick="return EmpQualitiesView(\'' + item.EducationGUID + '\');" href="javascript:void(0);"><span style="color: #43a9f5">' + item.CertificateCode + '</span></a></td>';
                innerHTML += '<td>' + CLCode + '</td><td>' + item.CSCode + '</td><td>' + GetCertificateDate + '</td><td>' + ZsEndDate + '</td></tr>';
                GetEmpQualitiesImg(item.EducationGUID, item.CertificateName);
            }
        }
        $("#EmpQualities").append(innerHTML);
        EmpQualitiesShowImg();
    });
}
//资格证书预览
function EmpQualitiesView(educationGUID) {
    ShowUpForm("../Person/PersonEmpCertInfo.aspx?opt=2&empGuid=" + empGuid + "&certGuid=" + educationGUID, 800, 650, top);
}
   
/*加载人员执业手册数据*/
function GetEmpQualitiesSC() {
    $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", { "action": "Qualitie", "empGuid": empGuid, "type": manual, "areaCode": areaCode, "rand": Math.random() }, function (data) {
        var innerHTML = "";
        $("#EmpQualitiesSC").empty();
        if (data != null && data.length > 0) {
            var GetCertificateDate = "";
            var ZsEndDate = "";
            var CLCode ="";
            for (var i = 0, j = data.length; i < j; i++) {
                var item = data[i];
                if (item.GetCertificateDate != null && item.GetCertificateDate.length > 10) {
                    GetCertificateDate = item.GetCertificateDate.substring(0, 10);
                } else {
                    GetCertificateDate = item.GetCertificateDate;
                }
                if (item.ZsEndDate != null && item.ZsEndDate.length > 10) {
                    ZsEndDate = item.ZsEndDate.substring(0, 10);
                } else {
                    ZsEndDate = item.ZsEndDate == null ? "" : item.ZsEndDate;
                }
                CLCode = item.CLCode == null ? "" : item.CLCode;
                innerHTML += ' <tr><td><input  type="checkbox" id="' + item.EducationGUID + '" typeflag="' + item.TypeFlags + '" certCode="' + item.CertificateCode + '"/></td>';
                innerHTML += '<td>' + item.CertificateName + '</td><td><a onclick="return EmpQualitiesSCView(\'' + item.EducationGUID + '\');" href="javascript:void(0);"><span style="color: #43a9f5">' + item.CertificateCode + '</span></a></td>';
                innerHTML += '<td>' + CLCode + '</td><td>' + item.CSCode + '</td><td>' + GetCertificateDate + '</td><td>' + ZsEndDate + '</td></tr>';
            }
        }
        $("#EmpQualitiesSC").append(innerHTML);
    });
}
function EmpQualitiesSCView(educationGUID) {
    ShowUpForm("../Person/PersonEmpCertInfo.aspx?opt=2&empGuid=" + empGuid + "&certGuid=" + educationGUID + "&manual=" + manual, 800, 650);
}
  
//取得资格证书图片加载到人员相关图片begin
function GetEmpQualitiesImg(EducationGUID, CertificateName) {
    var html = ' <div class="corpImages empCertImg" >';
    html += '<img alt="点击查看大图" src="../images/photobg.jpg" class="pointer" width="150" height="150" funccode="PersonZG" syscode="EF" imgnm="' + EducationGUID + '"/>';
    html += '<div class="corpImagesTitle"><span>' + CertificateName + '</span></div></div>';
    $("#empUpImgDiv").append(html);
}
//点击预览图片事件
function EmpQualitiesShowImg() {
    $("#empUpImgDiv .empCertImg img").each(function () {
        var sysCode = $(this).attr("syscode");
        var funcCode = $(this).attr("funccode");
        var imgname = $(this).attr("imgnm");
        $(this).attr("src", "../Handlers/GetFileHandler.ashx?gettype=last&fileName=" + imgname + ".jpg&sysCode=" + sysCode + "&funcCode=" + funcCode + "&rand=" + Math.random());
        $(this).click(function () {
            ShowUpForm("../Enterprise/UploadFileShowList.aspx?fileName=" + imgname + "&fileType=.jpg&sysCode=" + sysCode + "&funcCode=" + funcCode, 800, 600);
        });
    });
} //end

/*人员证件图片身份证，职称，安全考核证处理*/
/*显示图片列表*/
function ShowImgList(imgObj, filename) {
    var sysCode = imgObj.attr("syscode");
    var funcCode = imgObj.attr("funccode");
    imgObj.click(function () {
        $.ligerDialog.open({ url: "../Enterprise/UploadFileShowList.aspx?filename=" + filename + "&funcCode=" + funcCode + "&sysCode=" + sysCode + "&fileType=.jpg&rand=" + Math.random(), width: 820, height: 650, title: '', isResize: true, buttons: [{ text: '关闭', onclick: function (item, dialog) { dialog.close(); } }] });
        return false;
    });
}
    
/*打开图片上传窗口*/
function GetImgList(imgObj, filename) {
    var sysCode = imgObj.attr("syscode");
    var funcCode = imgObj.attr("funccode");
    imgObj.click(function () {
        ShowUpForm("../UserControl/FileUploadList.aspx?filename=" + filename + "&FuncCode=" + funcCode + "&rand=" + Math.random(), 800, 600);
            return false;
    });
    }
    /*显示单张图片*/
    function ShowImg(imgObj) {
        var sysCode = imgObj.attr("syscode");
        var funcCode = imgObj.attr("funccode");
        var imgnm = imgObj.attr("imgnm");
        if (imgnm == "") {
            if (funcCode == "PersonKH") {
                imgnm = eduGuid;
            } else {
                imgnm = empGuid;
            }
        }
        imgObj.attr("src", "../Handlers/GetFileHandler.ashx?gettype=last&fileName=" + imgnm + ".jpg&sysCode=" + sysCode + "&funcCode=" + funcCode + "&rand=" + Math.random());
    }
    //身份证和职称显示事件
function EmpImgBtnClick() {
    $("#empUpImgDiv img").each(function () {
        var funcCode = $(this).attr("funccode");
        if (funcCode != "PersonKH") {
            ShowImgList($(this), empGuid);
        }
    });
    EmpImgUploadBtnClick();
}
//身份证和职称上传事件
function EmpImgUploadBtnClick() {
    $(".updloadbtn").each(function () {
        var funcCode = $(this).attr("funccode");
        if (funcCode != "PersonKH") {
            GetImgList($(this), empGuid);
        }
    });
}
/*显示头像图片*/
function ImgShow() {
    $("#personimg").attr("src", "../Handlers/GetFileHandler.ashx?gettype=last&fileName=" + empGuid + ".jpg&sysCode=EFNoWater&funcCode=Person&rand=" + Math.random());
}
/*显示相关图片小图--页面加载和上传返回更新，所相关图片事件*/
function ImgCardShow(code) {
    if (code.length > 0) {
        $("#empUpImgDiv img[funccode='" + code + "']").each(function () {
            ShowImg($(this));
        });
        return;
    }
    $("#empUpImgDiv img").each(function () {
        ShowImg($(this));
    });
}
/*身份证和职称放大镜预览图片*/
function ToImgZoom() {
    $(".imgZoom").each(function () {
        var funcCode = $(this).attr("funccode");
        if (funcCode != "PersonKH") {
            ShowImgList($(this), empGuid);
        }
    });
}
/*安全考核证图片处理*/
function PersonKHImgs(filename) {
    ShowImgList($("#PersonKHZoom"),filename);//显示
    ShowImgList($("#PersonKHImg"), filename);
    GetImgList($("#PersonKHUpImg"), filename); //上传
    GetImgList($("#PersonKHUp"), filename);
}
/*关闭窗口执行事件*/
function OnClientClose(args) {
    var arg = args;
    if (arg) {
        if (arg.Result == 1) {
            return;
        }
        var childWinName = arg.childWinName;
        switch (childWinName) {
            case "Cert"://资格证书
                GetEmpQualities();
                break;
            case "CertSC"://执业手册
                GetEmpQualitiesSC();
                break;
            case "Audit":
                // window.location = window.location.href;
                returnToParent(1);
                break;
            case "Specs":
                GetExpertSpeciality(true);
                GetExpertSpeciality(false);
                break;
            case "Relation":
                GetExpertRelation(1);
                GetExpertRelation(0);
                break;
            default://工作经历
                GetEmpWorkExperience();
                break;
        }
    }
    GetEmpUserLog(1, 10);
}
//审核关闭事件
function OnClientClose2(args) {
    var arg = args;
    if (arg) {
        if (arg.Result == 1) {
            return;
        }
        var childWinName = arg.childWinName;
        switch (childWinName) {
            case "Audit":
                top.ChildDialogCallBack = "OnClientCloseAudit";
                top.ChildDialogClose(1);
                //                    parent.OnClientCloseAudit(1);
                //                    window.parent.$.ligerDialog.close(); ////关闭dialog
                //                    parent.$(".l-dialog,.l-window-mask").hide(); ////去除父窗体遮罩层
                break;
        }
    }
}
//图片上传关闭事件
function OnClientCloseImg(args) {
    var arg = args;
    if (arg) {
        if (arg.Result == 1) {
            return;
        }
        switch (arg.funcCode) {
            case "Person":
                ImgShow();//头像
            default://其他
                ImgCardShow(arg.funcCode);
                break;
        }
    }
}
//------------关闭窗口返回人员guid，名称------------------
function OnCloseChangeEmp() {
    $("#EmpbtnClose").click(function () {
          
        $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", { "action": "EmpIsExist", "empGuid": empGuid, "areaCode": areaCode, "rand": Math.random() }, function (data) {
            var result = data.Result;
            //正常
            if (!result) {
                OpenConfirmFn("人员信息尚不存在，您确定要关闭窗口！", CloseCanCelEmpCallBackFn);
                return false;
            }
            OpenConfirmFn("您确定要关闭窗口！", CloseGetEmpCallBackFn);
        });
    });
}
//返回人员信息关闭窗口
function CloseGetEmpCallBackFn(yes) {
    if (!yes) {
        return false;
    }
    var oArg = { EmpGuid: empGuid, EmpName: $("#txtName").val() };
    window.parent.OnClientCloseGetEmp(oArg);
    CloseChildEmpWin();
}
//直接关闭窗口
function CloseCanCelEmpCallBackFn(yes) {
    if (!yes) {
        return false;
    }
    CloseChildEmpWin();
} 
//end---------------------------------
//关闭子窗口事件
function CloseChildEmpWin() {
    window.parent.$.ligerDialog.close(); ////关闭dialog
    parent.$(".l-dialog,.l-window-mask").hide(); ////去除父窗体遮罩层
    parent.window.focus(); //返回焦点
}
/*打印*/
function EmpQualscPrint(tbodyname) {
    if (!EmpDelCheck(tbodyname)) {
        return false;
    }
    ///取得证书类型
    var keyId = "";
    var certCode = "";
    $("input[type='checkbox']:checked", $("#" + tbodyname)).each(function () {
        keyId += $(this).attr("typeflag") + ",";
        certCode += $(this).attr("certCode") + ",";
    });
    if (keyId != "") {
        keyId = keyId.substring(0, keyId.indexOf(","));
    }
    if (certCode != "") {
        certCode = certCode.substring(0, certCode.indexOf(","));
    }
    window.open("../Person/PersonEmpCertPrintAdd.aspx?empGuid=" + empGuid + "&typeflag=" + keyId + "&certCode=" + certCode);
    return false;
}
/*关闭窗口*/
function GetRadWindow() {
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow;
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
    return oWindow;
}
function returnToParent() {
    if (model == 1) {
        var oWnd = GetRadWindow();
        oWnd.close();
    }
}
function returnToParent(result) {
    if (model == 1) {
        var oArg = new Object();
        oArg.Result = result;
        var oWnd = GetRadWindow();
        if(oWnd)oWnd.close(oArg);
    }
}
/*弹出提示*/
function OpenAlert(text) {
    $.ligerDialog.warn(text);
    return false;
}
function OpenAlertFn(text) {
    radalert(text, 330, 150, '提示', alertCallBackFn, null); 
    return false;
}
function alertCallBackFn(arg) {
    window.location = backUrl;
}
function OpenConfirmFn(text, confirmCallBackFn) {
    $.ligerDialog.confirm(text, '', confirmCallBackFn);
    return false;
}

